package com.portal.bussniess.web;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.portal.back.service.ISysContentService;
import com.portal.back.service.ISysCustomService;
import com.portal.back.service.ISysMessageService;
import com.portal.back.service.ISysProfessionalService;
import com.portal.back.service.impl.SysContentService;
import com.portal.back.service.impl.SysCustomService;
import com.portal.back.service.impl.SysMessageService;
import com.portal.back.service.impl.SysProfessionalService;
import com.portal.base.web.BaseAction;
import com.portal.domain.SysContent;
import com.portal.domain.SysCustom;
import com.portal.domain.SysMessage;
import com.portal.domain.SysProfessional;
import com.portal.util.common.DateTimeUtil;

/**
 * 前台页面数据控制action
 * 
 * @author FC
 * 
 */
@SuppressWarnings("serial")
public class StageAction extends BaseAction {
	private SysContent content;
	private List<SysContent> contentList;
	private SysProfessional sp;
	private List<SysProfessional> spList;
	private SysCustom sc;
	private List<SysCustom> scList;
	private SysCustom custom;
	private List<SysCustom> customList;
	private ISysContentService contentService;
	private ISysProfessionalService proService;
	private ISysCustomService scService;
	private ISysCustomService customService;
	private String pageNo;
	private SysMessage sysMessage;
	private ISysMessageService messageSevice;

	public String getPageNo() {
		return pageNo;
	}

	public void setPageNo(String pageNo) {
		this.pageNo = pageNo;
	}

	public StageAction() {
		contentService = new SysContentService();
		proService = new SysProfessionalService();
		scService = new SysCustomService();
		customService = new SysCustomService();
		messageSevice = new SysMessageService();
	}

	public String home() {
		try {
			content = contentService.getComany();
			ActionContext context = ActionContext.getContext();
			context.put("about", content);
			contentList = contentService.getContent(0, 5, "5");
			context.put("newsList", contentList);
			spList = proService.find(0, 3);
			context.put("proList", spList);
			scList = scService.find(0, 20, "2");
			context.put("alList", scList);
			content = contentService.getConnection();
			context.put("connection", content);
		} catch (Exception e) {
			log.error("首页加载错误" + DateTimeUtil.getCurrentDate1(), e);
		}
		return "home";
	}

	public String thread() {
		try {
			String type = request.getParameter("type");
			if (null == type)
				type = "";
			if (null == pageNo || "".equals(pageNo))
				pageNo = "1";
			ActionContext context = ActionContext.getContext();
			scList = scService.find(0, 20, "2");
			context.put("proList", scList);
			context.put("type", type);
			if ("1".equals(type) || "2".equals(type) || "3".equals(type)
					|| "4".equals(type)) {
				content = contentService.getContent(type);
				return "about";
			} else if ("5".equals(type) || "6".equals(type) || "7".equals(type)) {
				contentList = contentService.getContent(
						(new Integer(pageNo) - 1) * 5, 5, type);
				return "news";
			} else if ("8".equals(type) || "9".equals(type) || "8".equals(type)) {
				content = contentService.getContent(type);
				return "service";
			} else if ("14".equals(type) || "15".equals(type)) {
				content = contentService.getContent(type);
				return "employee";
			} else if ("99".equals(type) || "98".equals(type)) {
				content = contentService.getContent(type);
				return "connect";
			} else if ("100".equals(type)) {
				spList = proService.find(0, 3);
				return "hysd";
			} else if ("101".equals(type) || "102".equals(type)) {
				customList = customService.find((new Integer(pageNo) - 1) * 12,
						12, type.substring(2));
				return "cus";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "about";
	}

	public String showInfo() {
		try {
			String type = request.getParameter("type");
			String id = request.getParameter("id");
			if ("1".equals(type)) {
				content = contentService.getById(id);
				return "news_show";
			} else if ("2".equals(type)) {
				custom = customService.getById(id);
				return "custom_show";
			}
		} catch (Exception e) {

		}
		return null;
	}
	
	public String saveMessage() {
		try{
			messageSevice.saveMessage(sysMessage);
		}catch (Exception e) {
			log.error("留言保持失败", e);
		}
		return "message";
	}

	public SysContent getContent() {
		return content;
	}

	public void setContent(SysContent content) {
		this.content = content;
	}

	public List<SysContent> getContentList() {
		return contentList;
	}

	public void setContentList(List<SysContent> contentList) {
		this.contentList = contentList;
	}

	public SysProfessional getSp() {
		return sp;
	}

	public void setSp(SysProfessional sp) {
		this.sp = sp;
	}

	public List<SysProfessional> getSpList() {
		return spList;
	}

	public void setSpList(List<SysProfessional> spList) {
		this.spList = spList;
	}

	public SysCustom getSc() {
		return sc;
	}

	public void setSc(SysCustom sc) {
		this.sc = sc;
	}

	public List<SysCustom> getScList() {
		return scList;
	}

	public void setScList(List<SysCustom> scList) {
		this.scList = scList;
	}

	public SysCustom getCustom() {
		return custom;
	}

	public void setCustom(SysCustom custom) {
		this.custom = custom;
	}

	public List<SysCustom> getCustomList() {
		return customList;
	}

	public void setCustomList(List<SysCustom> customList) {
		this.customList = customList;
	}

	public SysMessage getSysMessage() {
		return sysMessage;
	}

	public void setSysMessage(SysMessage sysMessage) {
		this.sysMessage = sysMessage;
	}

}
